package com.bootx.predict.util;

import com.bootx.predict.pojo.RedPacketBatch;
import com.bootx.predict.pojo.RedPacketRecord;

import java.util.ArrayList;
import java.util.List;

public class PredictUtils {

    public static boolean isAmountOdd(double amount) {
        int cents = (int) Math.round(amount * 100);
        int units = cents % 10;
        int tens = (cents / 10) % 10;
        return ((units + tens) % 2) == 1;
    }

    public static List<RedPacketRecord> parseData(List<RedPacketBatch> batches) {
        List<RedPacketRecord> records = new ArrayList<>();
        for (RedPacketBatch batch : batches) {
            for (RedPacketBatch.RedPacketDetail d : batch.getRedPackets()) {
                records.add(new RedPacketRecord(batch.getBatchId(), d.getIndex(), d.getAmount(), d.getOpenTime()));
            }
        }
        return records;
    }
}
